package com.pine.dcts.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pine.dcts.common.DctsConstant;
import com.pine.dcts.entity.PluginInfo;
import com.pine.dcts.mapper.PluginMapper;
import com.pine.dcts.query.PluginInfoQuery;
import com.pine.dcts.service.PluginInfoService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PluginInfoServiceImpl extends ServiceImpl<PluginMapper, PluginInfo>  implements PluginInfoService  {
    @Override
    public List<PluginInfo> selectEnabledList() {
        LambdaQueryWrapper<PluginInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PluginInfo::getStatus, DctsConstant.YES);
        return this.list(wrapper);
    }

    @Override
    public PluginInfo selectOneByNameAndType(String name, String type) {
        LambdaQueryWrapper<PluginInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PluginInfo::getName, name);
        wrapper.eq(PluginInfo::getType, type);
        return getOne(wrapper);
    }

    @Override
    public IPage<PluginInfo> selectPage(PluginInfoQuery query) {
        Page page = query.getPage();
        LambdaQueryWrapper<PluginInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(PluginInfo::getInstallTime);
        return page(page,wrapper);
    }
}
